package com.poetry.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.poetry.domain.po.History;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface HistoryMapper extends BaseMapper<History> {
    @Select("SELECT bh.*, p.title AS poem_title, p.author AS author " +
            "FROM history bh " +
            "JOIN poem p ON bh.poem_id = p.id " +
            "WHERE bh.user_id = #{userId} " +
            "ORDER BY bh.viewed_at DESC " +
            "LIMIT #{limit}")
    List<History> selectHistoryWithPoemInfo(@Param("userId") Integer userId,
                                            @Param("limit") int limit);
}
